package com.gxycoding.websocket.config;

import com.gxycoding.websocket.common.ConstantUtil;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import javax.websocket.server.ServerEndpointConfig.Configurator;

/**
 * Description(重写ServerEndpointConfig.Configurator的modifyHandshake方法)
 * author: Gao xueyong
 * Create at: 2020/7/15 9:01 下午
 */
public class GetHttpSessionConfigurator extends Configurator {

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        HttpSession httpSession = (HttpSession) request.getHttpSession();
        sec.getUserProperties().put(HttpSession.class.getName(), httpSession);
        sec.getUserProperties().put(ConstantUtil.clinetIp, httpSession.getAttribute(ConstantUtil.clinetIp));
    }
}
